// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. For activeness
//   Cell 3 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short following = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Unfinished Golem");
	set_attack_bonus(ME,6);

	if (gf(get_memory_cell(1),get_memory_cell(2)) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; 
	if (gf(get_memory_cell(1),get_memory_cell(2)) == 0)
		end();
	if ((get_attitude(ME) >= 10) && (gf(get_memory_cell(1),get_memory_cell(2)) == 2))
		sf(get_memory_cell(1),get_memory_cell(2),1);
	if (gf(get_memory_cell(1),get_memory_cell(2)) == 2)
		following = 1;
		
	if ((get_memory_cell(2) == 11) && 
		(gf(get_memory_cell(1),get_memory_cell(2)) == 2) && (((num_chars_in_group(1) == 0) && (gf(36,23) > 0) && (dist_to_nav_point(ME,0) <= 12)) || (gf(34,22) > 0))) {
		force_char_status(ME,20,10);
		sf(get_memory_cell(1),get_memory_cell(2),3);
		begin_talk_mode(15);
		}
		
	if (gf(get_memory_cell(1),get_memory_cell(2)) == 3) {
		force_char_status(ME,20,10);
		end();
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if (following) {
		if (dist_to_pc() > 12) {
			print_named_str(ME,"runs to catch up with you.");
			telep_char_to_char(ME,pc_num(),FALSE);
			}
			else maintain_dist_to_char(ME,pc_num(),2);
		}		
		else fidget(ME,25);

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (gf(get_memory_cell(1),get_memory_cell(2)) == 0)
		set_state(START_STATE);
	if (gf(get_memory_cell(1),get_memory_cell(2)) == 3) 
		set_state(START_STATE);
	if (target_ok() == FALSE)
		set_state(START_STATE);
	
	// if friendly, attacks more
	if (get_attitude(ME) < 10)
		set_new_abil(ME,20);
		else set_new_abil(ME,0);
		
	do_attack();
break;

beginstate TALKING_STATE;
	if (gf(get_memory_cell(1),get_memory_cell(2)) == 2) {
		print_str("Talking: It doesn't respond. It can't talk. It just follows");
		print_str("  you around.");
		}
		else print_str("Talking: It doesn't respond.");
break;